package com.taotao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EUDataGridResult;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.service.ContentService;
import com.taotao.service.RedisService;

@Controller
public class ContentController {
	@Autowired
	private ContentService contentService;
	@Autowired
	private RedisService redisService;

	@RequestMapping(value = "/content/query/list")
	@ResponseBody
	public EUDataGridResult getContentList(long categoryId, int page, int rows) {
		return contentService.getContentList(categoryId, page, rows);
	}

	@RequestMapping(value = "/content/save", method = RequestMethod.POST)
	@ResponseBody
	public TaotaoResult saveContent(long categoryId, String title, String 
			subTitle, String titleDesc, String url,
			String pic, String pic2, String content) {
		redisService.sysncContent(categoryId);
		return contentService.saveContent(categoryId, title, subTitle, titleDesc, url, pic, pic2, content);
	}
	
	@RequestMapping(value="/rest/content/edit", method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult editContent(long categoryId, long id, String title, String 
			subTitle, String titleDesc, String url,
			String pic, String pic2, String content) {
		redisService.sysncContent(categoryId);
		return contentService.editContent(categoryId, id, title, subTitle, titleDesc, url, pic, pic2, content);
	}
	
	@RequestMapping(value="/content/delete")
	@ResponseBody
	public TaotaoResult deleteContent(long ids) {
		long categoryId = (long) contentService.deleteContent(ids).getData();
		redisService.sysncContent(categoryId);
		return TaotaoResult.ok(categoryId);
	}
}
